﻿// -----------------------------------------------------------------------
// <copyright file="RichTextBoxHelpers.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace LogManager.Gui.UI.Helpers
{
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public static class RichTextBoxHelpers
    {     
        public static string GetText(this RichTextBox richTextBox)
        {
            // use a TextRange to fish out the Text from the Document
            TextRange textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
            return textRange.Text.Replace(Environment.NewLine, "");
        }

        public static void appendTixt(this RichTextBox rtbx, string str)
        {
            rtbx.AppendText(str);
            rtbx.ScrollToEnd();
        }

        public static void addTextPair(this RichTextBox rtbx, string item, string value)
        {
            //prefixe
            Run block_prefix = new Run(item);
            block_prefix.Foreground = System.Windows.Media.Brushes.DarkGray;
            block_prefix.FontWeight = FontWeights.Bold;
            //suffixe
            Run block_dossierDest = new Run(value);
            //ajout au paragraph
            Paragraph para = new Paragraph();
            para.Inlines.Add(block_prefix);
            para.Inlines.Add(block_dossierDest);
            para.Margin = new Thickness(0);
            //ajout au richtextbox
            rtbx.Document.Blocks.Add(para);
        }

        public static void addTextTitle(this RichTextBox rtbx, string txt)
        {
            //prefixe
            Run block_prefix = new Run(txt);
            block_prefix.Foreground = System.Windows.Media.Brushes.Black;
            block_prefix.FontWeight = FontWeights.Bold;
            block_prefix.TextDecorations = TextDecorations.Underline;
            //ajout au paragraph
            Paragraph para = new Paragraph();
            para.Inlines.Add(block_prefix);
            para.Margin = new Thickness(0);
            //ajout au richtextbox
            rtbx.Document.Blocks.Add(para);
        }
    }
}
